function getData()
	  {
			if($("#firstKind").val()!=0)
			{
			 firstkind=$("#firstKind").val(); 
			  secondkindid = $("#secondKind").val(); 
			  $("#secondkindid").val(secondkindid);
			  $("#firstkindid").val(firstkind); 
			  //不能要dataType=json，不然解析不出来。。。。
			  $.ajax({   
				  type: "POST",  
				  url: "/TradeBook/view/TraderBook_ControlBook/dynamicAddSecondKinds",  
				  data: 'firsertkind=' + firstkind,  
				  timeout: 15*1000,
				  success: function(data){					
					  var member = eval("("+data+")");   
					
					  var second="<option value='0'>---請選擇---</option>";
	               for(var i=0;i<member.length;i++)
	               	{
	            	var test="<option value='"+member[i].secondkindId+"'>"+member[i].secondkindName+"</option>";
	               	second+=test;
	               	
	               	}
	               $("#secondKind").html(second);
				  },
				  error:function(result){
		              	alert("ASd");
		              }
			  });
			}
	  }
function getMajorInfo(id,secondId)
{
	    var rID = "#" +id+"";
	    var secondID = "#" + secondId + "";
		if($(rID).val()!=0)
		{
		 provinceId=$(rID).val();
		 var uri ="/TradeBook/view/TraderBook_TraderCenter/traderMajor";
		  //不能要dataType=json，不然解析不出来。。。。
		  $.ajax({   
			  type: "POST",  
			  url: uri,  
			  data: 'id=' + provinceId,  
			  timeout: 15*1000,
			  success: function(data){  
				  var member=eval("("+data + ")"); //正确写法
				  var second= "<option value='0'>---专业---</option>";
				  for(var i=0;i<member.length;i++)
	               	{						 
	            	var test="<option value='"+member[i].majorId+"'>"+member[i].majorName+"</option>";
	            	second+=test; 	
	               	}
				$(secondID).html(second);
			  },
			  error:function(result){
	              	alert("ASd");
	              }
		  });
      }
}
$(this).ready(function() {
	$.validator.addMethod('checkDif1',function(value,element){
		if(($("#traderMajor").val()==value || $("#traderMajor2").val()==value ||$("#traderMajor3").val()==value ) && value!=0)
		{
			
		  return false;	
		}else{
			return true;
		}
	});
	$.validator.addMethod('checkDif2',function(value,element){
		if(($("#traderMajor").val()==value || $("#traderMajor1").val()==value ||$("#traderMajor3").val()==value ) && value!=0)
		{
		  return false;	
		}else{
			return true;
		}
	});
	$.validator.addMethod('checkDif3',function(value,element){
		
		if(($("#traderMajor").val()==value || $("#traderMajor2").val()==value ||$("#traderMajor1").val()==value ) && value!=0)
		{
		  return false;	
		}else{
			return true;
		}
	});
	$.validator.addMethod('checkDate',function(value,element){
		var reg = /^\d{4}-\d{2}-\d{2}$/;
		var date = value.split('-');		
		return reg.test(value) && date[1]<=12 && date[2]<=31;
	},"请输入正确的日期,如:yy-mm-dd");
	$.validator.addMethod('checkBarCode',function(value,element){
		var reg = /^\d{13}$/;
		return reg.test(value);
	});
	$.validator.addMethod('checkNumber',function(value,element){
		var reg = /^\d*$/;
		return reg.test(value);
	});
	// validate signup form on keyup and submit
	$("#signupForm").validate({
		rules: {
			traderAcademy: {
				required:true,
				min:1
			},
			traderMajor:  {
				
				
			},traderMajor1:  {
				checkDif1:true
				
			},traderMajor2:  {
				checkDif2:true
			},traderMajor3:  {
				checkDif3:true
			},
			firstKind: {
				required:true,
				min:1
			},
			secondKind:  {
				required:true,
				min:1
			},
			bName: {
				required: true	
			},
			bAuthor: {
				required: true
			},
			bFirmpublication: {
				required: true
			},
			bNowprice:{ 
				required:true,
				min:0
			},
		bTimepublication: {
			checkDate:true,
			required:true
		},
		bBarcode: {
			checkBarCode:true,
			required:true
		},
		bDegree: "required",
		bCount:"required"
		},
		messages: {
			traderAcademy: {
				required:'请选择',
				min:'请选择'
			},
			traderMajor:{
				required:'请选择',
				min:'请选择'
			},traderMajor1:  {
				checkDif1:"不能选相同专业"	
			},traderMajor2:  {
				checkDif2:"不能选相同专业"
			},traderMajor3:  {
				checkDif3:"不能选相同专业"	
			},
			firstKind: {
				required:'请选择',
				min:'请选择'
			},
			secondKind:{
				required:'请选择',
				min:'请选择'
			},
			bName: {
				required: "必填",				
			},
			bAuthor: {
				required: "必填",	
			},
			bFirmpublication: "必填",
			bNowprice : {
				required: "必填",
				min: "格式错误"
			},bTimepublication: {
				checkDate:"请输入正确的日期",
				required: "必填"
			},
			bBarcode:{required:"必填",
				checkBarCode:"请填写14位整数"	
			},
			bDegree: "必填",
			bCount:"必填"
		},
		errorPlacement: function(error, element) {                             //错误信息位置设置方法  
			 error.appendTo( element.parent().parent() );                            //这里的element是录入数据的对象  
		 },
		 errorElement:"span",
		 errorClass:"invalid"
		
	});
	 var yearFrom=new Date().getYear()-50+1900;
     var yearTo=new Date().getYear()+1900;   

    $('#dateinput').datepicker({  
    dateFormat: 'yy-mm-dd',  
    buttonImage:'/TradeBook/images/calender.png',  
    buttonImageOnly: true,  
    showOn: 'both',
    yearRange: yearFrom+':'+yearTo,
    clearText:'清除',
    closeText:'关闭',
    prevText:'前一月',
    nextText:'后一月',
    currentText:' ',
    monthNamesShort:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
    changeYear: true ,
    changeMonth: true,
    dateFormat: 'yy-mm-dd' ,
    dayNamesMin: ['一', '二', '三', '四', '五', '六', '日']  ,
    duration: 'slow'
    }); 
});
$(function(){
	  var firstkind = "";
	  var secondkindid="";
	  getData();
	//  $("#btn").attr("disabled")==true;
	$("#firstKind").change(function(){
	    getData();	
	});
	  $("#secondKind").change(function(){
		  firstkind=$("#firstKind ").get(0).selectedIndex;
		  secondkindid = $("#secondKind").get(0).selectedIndex;
		  $("#secondkindid").val(secondkindid);
		  $("#firstkindid").val(firstkind);  
	  });
});
$(document).ready(function() { 
	$("#picture").change(function(evt){
        var files = evt.target.files; 
        readfile(files);
    });
    //设计一段比较流行的滑动样式  
    $('#drop_zone_home').hover(function() {  
        $(this).children('p').stop().animate({  
            top : '0px'  
        }, 200);  
    }, function() {  
        $(this).children('p').stop().animate({  
            top : '-44px'  
        }, 200);  
    });  

    //要想实现拖拽，首页需要阻止浏览器默认行为，一个四个事件。  
    $(document).on({  
        dragleave : function(e) { //拖离  
            e.preventDefault();  
            $('.dashboard_target_box').removeClass('over');  
        },  
        drop : function(e) { //拖后放  
            e.preventDefault();  
        },  
        dragenter : function(e) { //拖进  
            e.preventDefault();  
            $('.dashboard_target_box').addClass('over');  
        },  
        dragover : function(e) { //拖来拖去  
            e.preventDefault();  
            $('.dashboard_target_box').addClass('over');  
        }  
    });        
    //================上传的实现  
    var box = document.getElementById('target_box'); //获得到框体  
    box.addEventListener("drop", function(e) {  
        e.preventDefault(); //取消默认浏览器拖拽效果  
        
        var fileList = e.dataTransfer.files; //获取文件对象  
        //fileList.length 用来获取文件的长度（其实是获得文件数量）  
        //检测是否是拖拽文件到页面的操作    
        if (fileList.length == 0) {  
            $('.dashboard_target_box').removeClass('over');  
            return;  
        }  
        //检测文件是不是图片  
        if (fileList[0].type.indexOf('image') === -1) {  
            $('.dashboard_target_box').removeClass('over');  
            return;  
        }  
        readfile(fileList);
        //var img = window.webkitURL.createObjectURL(fileList[0]);  
        //拖拉图片到浏览器，可以实现预览功能  
        xhr = new XMLHttpRequest();  
        xhr.open("post", "/TradeBook/view/TraderBook_ControlBook/upload",
					true);
			xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");

			var fd = new FormData();
			fd.append('files', fileList[0]);

			xhr.send(fd);
		}, false);
    function readfile(fileList)
    {
    	for (var i = 0, f; f = fileList[i]; i++) {
	           if (!f.type.match('image.*')) {
	             continue;
	           }       	          
	           var reader = new FileReader();
	           reader.onload = (function(theFile) {
	             return function(e) {                                
		       //       $("#photo").attr("src",e.target.result);
		              var div = document.getElementById("photo");
		              var img = document.createElement("img");
		              img.src=e.target.result;
		              img.width =100;
		              img.height=80;
		              img.style.margin = "4px 4px 4px 0";
		              div.appendChild(img);
	             };
	           })(f);
	           reader.readAsDataURL(f);
	         }
    };
	});